﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Logis.Utility.Log;
namespace InTelReceiver
{
    public partial class Form_InTelReceiver : Form
    {
        public Form_InTelReceiver()
        {
            InitializeComponent();

            this.button_Start_Click(null, null);

        }

        private void button_Refresh_Click(object sender, EventArgs e)
        {
            string[] strary = InTelServerManager.getInstance().getLog();

            foreach (string str in strary)
            {
                this.listBox_Log.Items.Insert(0, str);
            }

            while (this.listBox_Log.Items.Count > 5000)
            {
                this.listBox_Log.Items.RemoveAt(this.listBox_Log.Items.Count - 1);
            }
        }

        private void button_Start_Click(object sender, EventArgs e)
        {
            LogManager.getInstance().initial("InTelManager");
            InTelServerManager.getInstance().initialReceive();
            InTelServerManager.getInstance().initialListen();
            this.button_Refresh_Click(null, null);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string str = this.textBox1.Text;
            InTelServerManager.getInstance().processCMD(System.Text.Encoding.Default.GetBytes(str));
        }

        private void Form_InTelReceiver_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("是否關閉", "是否", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                InTelServerManager.getInstance().shutdown();
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}